﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Security;
using NS.Utilities;
using NS.BLL.Systems;
using NS.Model.Systems;

public partial class Systems_PowerManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            lbxAvailableRoles.Attributes.Add("onchange", "doTest()");
            RefreshAvailableRolesListBox();
        }
    }
    private void RefreshAvailableRolesListBox()
    {
        lbxAvailableRoles.SelectedIndex = -1;
        lbxAvailableRoles.DataSource = RoleService.GetRoleByWeights(100);
        lbxAvailableRoles.DataBind();
        if (lbxAvailableRoles.Items.Count == 0)
        {
            lblRoleInfoText.Text = "没有角色";
            lbxAvailableRoles.Visible = false;
        }
        else
        {
            lblRoleInfoText.Text = "已有角色";
            lbxAvailableRoles.Visible = true;
        }
    }

    [WebMethod]
    public static string getMenuData(string Roles)
    {
        return PowerService.GetMenuString(Roles);
    }
    [WebMethod]
    public static void saveData(string strMenuID, string strRolesName)
    {
        PowerService.DeletePowerByRolesName(strRolesName);
        if (strMenuID.Length > 0)
        {
            strMenuID = strMenuID.Substring(0, strMenuID.Length - 1);
            string[] MenuID = strMenuID.Split(',');
            foreach (string s in MenuID)
            {
                Power Model = new Power();
                Model.MenuID = Int64.Parse(s.Trim());
                Model.RolesName = strRolesName;
                PowerService.Insert(Model);
            }
        }
    }
}